#ifndef ZJ_BTOOLS_H
#define ZJ_BTOOLS_H

#include <stdio.h>
#define BIT_WIDTH 32
void BinaryPrint(int n)
{
    printf("%5d(10)=", n);
    int A[BIT_WIDTH], j, sc, i, t;
    memset(A, 0, sizeof(A));
    if (n >0)
        for (i = BIT_WIDTH - 1; i >= 0; i--)
            A[i] = n &1, n >>= 1;
    else if(n<0)
    {
        for (n =  - n, i = BIT_WIDTH - 1; i >= 0; i--)
            A[i] = n &1, n >>= 1;
        for (A[0] = i = 1; i < BIT_WIDTH; i++)
            A[i] = 1-A[i];
        for (sc = 1, i = BIT_WIDTH - 1; i >= 0 && sc; i--)
            t = A[i] + sc, sc = t >> 1, A[i] = t &1;
    }
    for (i = 0; i < BIT_WIDTH; i++)
    {
        printf("%d", A[i]);
        if(i%8==7)
            putchar(' ');
    }
    printf("(2)\n");
}


#endif /* ZJ_BTOOLS_H */
